<template>
	<view class="">
		<u-navbar :isFixed="true" title="授权" :borderBottom="false"></u-navbar>
	</view>
</template>

<script>
	var _this
	export default {
		data() {
			return {

			}
		},
		onLoad() {
			_this = this
			_this.getdata()
		},
		onShow() {

		},
		methods: {
			getdata() {
				uni.getProvider({
					service: 'oauth',
					success: function(res) {
						//微信登录
						if (res.provider.includes('weixin')) {
							uni.login({
								provider: 'weixin',
								success(res) {
									_this.authResult=res.authResult
									console.log(res,'login')
									
									wx.getUserInfo({
										provider: 'weixin',
										success: function(res) {
											_this.user = res.userInfo
											console.log(res.userInfo,'getUserInfo')
											let userInfo = res.userInfo;
											_this.$api.post("wechatauth", {
													openId: userInfo.openId,
													nickName: userInfo.nickName,
													gender: userInfo.gender,
													city: userInfo.city,
													province: userInfo.province,
													country: userInfo.country,
													avatarUrl: userInfo.avatarUrl,
													unionId: userInfo.unionId,
													client_uid: uni.getStorageSync('client_uid')
												}).then(data => {
												uni.setStorageSync("user", userInfo)
												uni.navigateTo({
													url: '/personal/cashOut'
												})
											});
										}
									})
								}
							})
						}
					}
				});
			}

		},
	}
</script>

<style>
</style>
